<script type="text/javascript">

    $(document).ready(function() {


        //$("#id").autoNumeric({aSep: '.', aDec: ','});


        $("#btn_pilih_lokasi").click(function() {
            //alert('aaa');
            $("#dialog-lokasi").dialog('open');
        });

        $("#btn_pilih_barang").click(function() {
            $("#dialog-barang").dialog('open');
        });

    });


    //        function PilihLokasi(aa){
    //            $("#kode_png").val(kode_png);
    //            $("#nama_png").val(nama_png);
    //
    //            $("#dialog-lokasi").dialog('close');
    //        }



    function PilihLokasi(aa) {
        var cc = aa.split("#");
        $("#kode_png").val(cc[0]);
        //$("#kode_skpd").val(cc[1]);
        $("#nama_png").val(cc[1]);

        $("#dialog-lokasi").dialog('close');
    }


    function PilihBarang(aa) {
        var cc = aa.split("#");

        $("#kode_aset").val(cc[0]);
        $("#nama_kel").val(cc[1]);

        $("#dialog-barang").dialog('close');
    }




</script>

<?php
if (Yii::app()->user->hasFlash('success'))
    $this->widget('bootstrap.widgets.TbAlert', array());

$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
    'id' => 'horizontalForm',
    'type' => 'horizontal',
    'enableAjaxValidation' => false,
        ));
?>
<div class="form">


    <?php echo $form->errorSummary($model); ?>
    <div class="control-group ">
        <label class="control-label" >Kode KIB</label>
        <div class="controls">

            <?php
            $query = "select max(kode_ka) as kode from kib_a";

            $hasil = Yii::app()->db->createCommand($query)->queryRow();

            //echo $hasil['kode'];


            if ($hasil['kode'] == 0) {
                $kode = $hasil['kode'] = 1;
            } else {
                $kode = $hasil['kode'] + 1;
            }


            echo $form->textField($model, 'kode_ka', array('class' => 'span1', 'id' => 'kode', 'value' => $kode, 'readonly' => true, 'maxlength' => 50));
            ?>
        </div>
    </div>

    <div class="control-group ">
        <label class="control-label" >Kode Pengelola</label>
        <div class="controls">
            <div class="span3" style="margin-left:0;">
                <?php //echo $form->hiddenField($model, 'kode_png', array('class' => 'form-control', 'id' => 'kode_png', 'maxlength' => 20)); ?>
                <div class="input-group">
                    <!--input type="text" class="form-control" id="kode_skpd"-->
                    <?php echo $form->textField($model, 'kode_png', array('class' => 'form-control', 'id' => 'kode_png', 'maxlength' => 20)); ?>
                    <span class="input-group-btn">	
                        <?php
                        $this->widget('bootstrap.widgets.TbButton', array(
                            'type' => 'info',
                            'label' => 'F1',
                            'htmlOptions' => array('id' => 'btn_pilih_lokasi')
                        ));
                        ?>
                    </span>
                </div>
            </div>
        </div>
    </div>

    <div class="control-group ">
        <label class="control-label"></label>
        <div class="controls">
            <input type="text" class="span4" id="nama_png">
            <?php //echo $form->textField($model, 'kode_png', array('class' => 'span4', 'id' => 'nama_png',  'maxlength' => 50));  ?>
        </div>
    </div>

</div>
<div class="control-group ">
    <label class="control-label" ><b>Kode Barang</b></label>
    <div class="controls">
        <div class="span3" style="margin-left:0;">
            <div class="input-group">
                <?php echo $form->textField($model, 'kode_aset', array('class' => 'form-control', 'id' => 'kode_aset', 'maxlength' => 25)); ?>
                <span class="input-group-btn">	
                    <?php
                    $this->widget('bootstrap.widgets.TbButton', array(
                        'type' => 'info',
                        'label' => 'F2',
                        'htmlOptions' => array(
                            'id' => 'btn_pilih_barang',
                            'style' => 'padding-left:15px;',
                        )
                    ));
                    ?>
                </span>
            </div>
        </div>
    </div>
</div>

<div class="control-group ">
    <label class="control-label" >Nama Barang</label>
    <div class="controls">
        <input type="text" class="span4" id="nama_kel">

        <?php //echo $form->textField($model, 'kode_png', array('class' => 'span4', 'id' => 'kode',  'maxlength' => 50));  ?>
    </div>
</div>

<div class="control-group ">
    <label class="control-label" >No Reg</label>
    <div class="controls">

        <?php echo $form->textField($model, 'no_reg', array('class' => 'span2', 'id' => 'kode', 'maxlength' => 50)); ?>
    </div>
</div>

<div class="control-group ">
    <label class="control-label" >Luas (M2)</label>
    <div class="controls">
        <?php echo $form->textField($model, 'luas', array('class' => 'span3', 'id' => 'kode', 'maxlength' => 50)); ?>
        Tahun Pengadaan
        <?php echo $form->textField($model, 'thn_png', array('class' => 'span1', 'id' => 'kode', 'maxlength' => 50)); ?>
    </div>
</div>

<div class="control-group ">
    <label class="control-label" >Alamat</label>
    <div class="controls">

        <?php echo $form->textField($model, 'lok_tanah', array('class' => 'span4', 'id' => 'kode', 'maxlength' => 50)); ?>
    </div>
</div>

<div class="control-group ">
    <label class="control-label" >Status Hak</label>
    <div class="controls">

        <?php
        echo $form->DropDownList($model, 'sts_hak', array(
            'prompt' => '',
            '0' => 'Hak Pakai',
            '1' => 'Hak Milik',
            '2' => 'Hak Guna Usaha',
            '3' => 'Hibah',
            '4' => 'Hak Pengelolaan'
                ), array('class' => 'span2'));
        ?>
    </div>
</div>

<div class="control-group ">
    <label class="control-label" >Sertifikat Tgl</label>
    <div class="controls">
        <div class="span2" style="margin:0;">
            <div class="input-group">
                <span class="input-group-addon"><i class="icon-calendar"></i></span>
                <?php
                $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                    'model' => $model,
                    //'attribute' => 'kode_png',
                    'attribute' => 'tgl_sertif',
                    // additional javascript options for the date picker plugin
                    'options' => array(
                        'yearRange' => 'c-50:c+20',
                    ),
                ));
                ?>
            </div>
        </div>	
    </div>
</div>
<div class="control-group ">
    <label class="control-label" >Sertf.No</label>
    <div class="controls">

        <?php echo $form->textField($model, 'no_sertif', array('class' => 'span2', 'id' => 'kode', 'maxlength' => 50)); ?>
    </div>
</div>

<div class="control-group ">
    <label class="control-label" >Pengguna</label>
    <div class="controls">
        <?php echo $form->textField($model, 'penggunaan', array('class' => 'span4', 'id' => 'kode', 'maxlength' => 50)); ?>
    </div>
</div>

<div class="control-group ">
    <label class="control-label" >Asal</label>
    <div class="controls">
        <?php echo $form->textField($model, 'asal', array('class' => 'span4', 'id' => 'kode', 'maxlength' => 50)); ?>
    </div>
</div>
<div class="control-group ">
    <label class="control-label" >Harga Perolehan</label>
    <div class="controls">
        <?php echo $form->textField($model, 'harga_prh', array('class' => 'span2', 'id' => 'kode', 'maxlength' => 50)); ?>
    </div>
</div>

<div class="control-group ">
    <label class="control-label" >Harga Pasar</label>
    <div class="controls">
        <?php echo $form->textField($model, 'harga_pasar', array('class' => 'span2', 'id' => 'kode', 'maxlength' => 50)); ?>
    </div>
</div>

<div class="control-group ">
    <label class="control-label" >Daftar Harga</label>
    <div class="controls">
        <?php
        echo $form->dropDownList($model, 'dasar_hrg', array(
            'prompt' => ' ',
            'NJOP' => 'NJOP',
            'Pasar' => 'Pasar',
                ), array('class' => 'span2'));
        ?>
        Tahun Nilai
        <input type="text" class="span2" >
        <?php //echo $form->textField($model, 'kode_png', array('class' => 'span2', 'id' => 'kode',  'maxlength' => 50));  ?>
    </div>
</div>

<div class="control-group ">
    <label class="control-label" >Kondisi</label>
    <div class="controls">
        <?php
        echo $form->dropDownList($model, 'kondisi', array(
            'prompt' => '',
            'Baik' => 'Baik',
            'Rusak' => 'Rusak',
            'Rusak Berat' => 'Rusak Berat',
                ), array('class' => 'span2', 'id' => 'kode'));
        ?>
    </div>
</div>
<div class="control-group ">
    <label class="control-label">Keterangan</label>
    <div class="controls">
        <?php echo $form->textField($model, 'ket_aset', array('class' => 'span4', 'id' => 'kode', 'maxlength' => 50)); ?>
    </div>
</div>
<div class="control-group ">
    <label class="control-label" >Kode Milik</label>
    <div class="controls">
        <?php
        echo $form->dropDownList($model, 'kode_milik', array(
            'prompt' => '',
            '0' => 'Kabupaten/Kota',
            '1' => 'Propinsi',
            '2' => 'Negara',
                ), array('class' => 'span2', 'id' => 'kode', 'maxlength' => 50));
        ?>
    </div>
</div>

<div class="form-actions">
    <?php
    $this->widget('bootstrap.widgets.TbButton', array(
        'buttonType' => 'submit',
        'type' => 'success',
        'icon' => 'save',
        //'label' => $model->isNewRecord ? 'Simpan' : 'Update',
        'label' => 'Simpan',
    ));
    ?>
    <?php
    $this->widget('bootstrap.widgets.TbButton', array(
        'type' => 'primary',
        'label' => 'Cari',
        'icon' => 'search',
        'url' => Yii::app()->createUrl("/KIB/KibA/admin"),
        'htmlOptions' => array(
            'style' => 'margin-left:5px',
        ),
    ));
    ?>
    <?php
    $this->widget('bootstrap.widgets.TbButton', array(
        'buttonType' => 'reset',
        //'type' => 'primary',
        //'label' => $model->isNewRecord ? 'Batal' : 'Reset',
        'icon' => 'remove',
        'label' => 'Batal',
        'htmlOptions' => array(
            'style' => 'margin-left:5px;',
        ),
    ));
    ?>

    <?php $this->endWidget(); ?>
</div>


<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
    'id' => 'dialog-lokasi',
    'options' => array(
        'title' => 'Cari Data Lokasi',
        'overflow' => 'scroll',
        'width' => 900,
        'height' => 500,
        'autoOpen' => false,
    //'buttons' => array(
    //    'Ok' => 'js:function(){$(this).dialog("close")}',),
    ),
));
?>

<?php
Yii::app()->clientScript->registerScript('pengelola', "
			$('form#pengelola').submit(function(){
				$.fn.yiiGridView.update('Pengelola', {
					data: $(this).serialize()
				});
				return false;
			});
		
		");
?>

<form method="get" class="form-horizontal" action="<?php echo Yii::app()->createUrl($this->route); ?>" id="pengelola">
    <div class="alert alert-info">
        <div class="control-group">
            <label class="control-label">Kode Pengelola </label>
            <div class="controls">
                <input type="text" class="span3" name="Pengelola[kode_skpd]" id="pengelola_kode_skpd" /> 
            </div>
        </div>

        <div class="control-group">
            <label class="control-label">Nama Pengelola </label>
            <div class="controls">    
                <input type="text" class="span3" name="Pengelola[nama_png]" id="pengelola_nama_png" />
                <!--button class="btn btn-primary" id="btn_search" type="submit" name="btn_search">Cari</button-->
            </div>
        </div>

        <?php
        $this->widget('bootstrap.widgets.TbButton', array(
            'buttonType' => 'submit',
            //'type' => 'primary',
            'icon' => 'search',
            'htmlOptions' => array(
                'id' => 'btn_search',
                'style' => 'margin-left:20px;',
            ),
            'label' => 'Cari',
        ));
        ?>
    </div>
</form>



<?php
$this->widget('bootstrap.widgets.TbGridView', array(
    'id' => 'Pengelola',
    'dataProvider' => $modelPengelola->search(),
    'type' => 'striped bordered condensed',
    //'htmlOptions' => array('style' => 'width:130%'),
    'columns' => array(
        array(
            'header' => 'Kode Pengelola',
            'value' => '$data->kode_skpd',
        ),
        array(
            'header' => 'Nama Pengelola',
            //'htmlOptions' => array('style' => 'text-align:center'),
            'value' => '$data->nama_png',
        ),
        //array(
//            'value' => 'CHtml::submitButton("Pilih",
//                array(
//                "kode_png"=>$data->kode_png,
//                "nama_png"=>$data->nama_png,                
//                "onClick"=>"PilihLokasi
//                ($(this).attr(\'kode_png\'),                
//                $(this).attr(\'nama_png\'))",
        array(
            'value' => 'CHtml::Button("Pilih",
                array("onClick" => "PilihLokasi(\'".$data->kode_png."#".
                $data->nama_png."\'
                )",
				"class"=>"btn btn-info",
				))',
            'type' => 'raw',
            'htmlOptions' => array(
                'style' => 'text-align:center',
            ),
        ),
    ),
));
?>


<?php
$this->endWidget('zii.widgets.jui.CJuiDialog');
?>


<!-- begin dialog-barang -->
<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
    'id' => 'dialog-barang',
    'options' => array(
        'title' => 'Cari Data Barang',
        'overflow' => 'scroll',
        'width' => 900,
        'height' => 500,
        'autoOpen' => false,
    //'buttons' => array(
    //    'Ok' => 'js:function(){$(this).dialog("close")}',),
    ),
));
?>

<?php
Yii::app()->clientScript->registerScript('barang', "
			$('form#barang').submit(function(){
				$.fn.yiiGridView.update('Barang', {
					data: $(this).serialize()
				});
				return false;
			});
		
		");
?>

<form method="get" class="form-horizontal" action="<?php echo Yii::app()->createUrl($this->route); ?>" id="barang">
    <div class="alert alert-info">
        <div class="control-group">
            <label class="control-label">Kode Barang </label>
            <div class="controls">
                <input type="text" class="span3" name="KelAset[kode_aset]" id="KelAset_kode_aset" /> 
            </div>
        </div>

        <div class="control-group">
            <label class="control-label">Nama Lokasi </label>
            <div class="controls">    
                <input type="text" class="span3" name="KelAset[nama_kel]" id="KelAset_nama_kel" />
                <!--button class="btn btn-primary" id="btn_search" type="submit" name="btn_search">Cari</button-->
            </div>
        </div>

<?php
$this->widget('bootstrap.widgets.TbButton', array(
    'buttonType' => 'submit',
    //'type' => 'primary',
    'icon' => 'search',
    'htmlOptions' => array(
        'id' => 'btn_search',
        'style' => 'margin-left:20px;',
    ),
    'label' => 'Cari',
));
?>
    </div>
</form>



<?php
$this->widget('bootstrap.widgets.TbGridView', array(
    'id' => 'Barang',
    'dataProvider' => $modelKelAset->KibA(),
    'type' => 'striped bordered condensed',
    //'htmlOptions' => array('style' => 'width:130%'),
    'columns' => array(
        array(
            'header' => 'Gol',
            'value' => '$data->gol',
        ),
        array(
            'header' => 'Bid',
            //'htmlOptions' => array('style' => 'text-align:center'),
            'value' => '$data->bid',
        ),
        array(
            'header' => 'Kel',
            //'htmlOptions' => array('style' => 'text-align:center'),
            'value' => '$data->kel',
        ),
        array(
            'header' => 'Sub Kel',
            //'htmlOptions' => array('style' => 'text-align:center'),
            'value' => '$data->subkel',
        ),
        array(
            'header' => 'Nama Barang',
            //'htmlOptions' => array('style' => 'text-align:center'),
            'value' => '$data->nama_kel',
        ),
        array(
            'header' => 'Kode Barang',
            //'htmlOptions' => array('style' => 'text-align:center'),
            'value' => '$data->kode_aset',
        ),
        //array(
//            'value' => 'CHtml::submitButton("Pilih",
//                array(
//                "kode_png"=>$data->kode_png,
//                "nama_png"=>$data->nama_png,                
//                "onClick"=>"PilihLokasi
//                ($(this).attr(\'kode_png\'),                
//                $(this).attr(\'nama_png\'))",
        array(
            'value' => 'CHtml::Button("Pilih",
                array("onClick" => "PilihBarang(\'".$data->kode_aset."#".
                $data->nama_kel."\'
                )",
				"class"=>"btn btn-info",
				))',
            'type' => 'raw',
            'htmlOptions' => array(
                'style' => 'text-align:center',
            ),
        ),
    ),
));
?>

<?php
$this->endWidget('zii.widgets.jui.CJuiDialog');
?>
